<template>
	<view class="content">
		<view class="uni-margin-wrap">
			<swiper class="swiper" circular :indicator-dots="indicatorDots" :autoplay="autoplay" :interval="interval"
				:duration="duration">
				<swiper-item>
					<image src="/static/banner.png" mode="aspectFill"></image>
				</swiper-item>
			</swiper>
		</view>
		<view class="nav-list flex between wrap">
			<view class="nav-item" style="color: #334897;">
				<image src="/static/bg1.png"></image>
				<view class="tit1">老师入口</view>
				<view class="tit2">管理教堂</view>
			</view>
			<view class="nav-item" style="color: #975641;">
				<image src="/static/bg2.png"></image>
				<view class="tit1">老师入口</view>
				<view class="tit2">管理教堂</view>
			</view>
			<view class="nav-item" style="color: #3C7578;">
				<image src="/static/bg3.png"></image>
				<view class="tit1">老师入口</view>
				<view class="tit2">管理教堂</view>
			</view>
			<view class="nav-item" style="color: #366799;">
				<image src="/static/bg4.png"></image>
				<view class="tit1">老师入口</view>
				<view class="tit2">管理教堂</view>
			</view>
		</view>
		<!-- 校园动态 -->
		<view class="newList">
			<view class="new-tit flex between">
				<view class="flex align"><text></text>校园动态</view>
				<view @click="toUrl('/pages/news/news')" class="more flex align">查看更多<u-icon name="arrow-right"></u-icon></view>
			</view>
			<view @click="toUrl('/pages/news/detail?id='+item.id+'')" class="list flex align"
				v-for="(item,index) in list" :key="index">
				<image :src="item.cover"></image>
				<view class="list-right">
					<view class="tit">{{item.title}}</view>
					<view class="eye flex between">
						<view>{{item.create_time}}</view>
						<view class="flex align">{{item.pv}}人阅读</view>
					</view>
				</view>
			</view>
			<uni-load-more :status="status" v-if="!empty" :content-text="loadText"></uni-load-more>
			<xw-empty :isShow="empty" text="暂无数据" textColor="#777777"></xw-empty>
			<!-- </view> -->
		</view>
	</view>
</template>

<script>
	import {
		articleQuery,
	} from '@/api/apiData.js';
	export default {
		data() {
			return {
				title: 'Hello',
				indicatorDots: true,
				autoplay: true,
				interval: 2000,
				duration: 500,
				totalPage: 1,
				page: 0,
				offset: 10,
				list: [],
				scrollTop: 0,
				empty: false,
				loadText: {
					loadmore: '点击或上拉加载更多',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				status: 'loadmore',
				channel_id: 1,
			}
		},
		onLoad() {
			this.getlist()
		},
		onPageScroll(e) {
			const that = this;
			that.scrollTop = e.scrollTop;
		},
		onReachBottom() {
			const that = this;
			that.getlist();
		},
		methods: {
			toUrl(u){
				uni.navigateTo({
					url:u
				})
			},
			async getlist() {
				console.log(888)
				const that = this;
				const {
					totalPage,
					page,
					offset,
					list,
					channel_id,
				} = that;
				let obj = {
					size: offset,
					page: page + 1,
					channel_id: 1
				};
				that.status = 'loading';
				if (totalPage > page) {
					let result = await articleQuery(obj);
					if (result.code == 1) {
						that.page = page + 1;
						if (result.data.total == 0) {
							that.empty = true;
							that.status = 'nomore';
							return;
						}
						that.empty = false;
						setTimeout(() => {
							that.status = 'loadmore';
						}, 500);
						that.list = list.concat(result.data.list);
						that.totalPage = Math.ceil(result.data.total / offset);
					}
				} else {
					setTimeout(() => {
						that.status = 'nomore';
					}, 500);
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.uni-margin-wrap {
		width: 690rpx;
		width: 100%;

		.swiper {
			height: 300rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

	}

	.nav-list {
		margin: 30rpx 24rpx;

		.nav-item {
			width: 49%;
			height: 188rpx;
			position: relative;

			image {
				position: absolute;
				width: 100%;
				height: 100%;
				top: 0;
				left: 0;
			}

			.tit1 {
				position: relative;
				font-size: 32rpx;
				font-weight: bold;
				margin: 24rpx 0 24rpx 24rpx;
			}

			.tit2 {
				position: relative;
				font-size: 24rpx;
				margin-left: 24rpx;
			}
		}
	}
	.newList {
		background: white;
		margin: 24rpx;
		padding: 16rpx 24rpx;
		.new-tit {
			text{
				background: #5690FB;
				width: 9rpx;
				height: 35rpx;
				border-radius: 5rpx;
				margin-right: 10rpx;
			}
	
			view:nth-child(1) {
				color: #017DF9;
				font-size: 28rpx;
			}
	
			.more {
				color: #757575;
				font-size: 24rpx;
			}
		}
	
		.list {
			border-bottom: solid 1rpx #DEDEDE;
			padding: 27rpx 0;
	
			image {
				width: 154rpx;
				height: 116rpx;
				object-fit: cover;
			}
	
			.list-right {
				margin-left: 12rpx;
				width: 73%;
	
				.tit {
					color: #333333;
					font-size: 26rpx;
					height: 72rpx;
					margin-bottom: 28rpx;
					overflow: hidden; //超出隐藏
					text-overflow: ellipsis; //溢出用省略号...显示
					display: -webkit-box; //将对象作为弹性伸缩盒子模型显示。
					-webkit-box-orient: vertical; //从上到下垂直 排列子元素（设置伸缩盒子的子元素排列方式）
					-webkit-line-clamp: 2; //表示显示的行数合上面两个属性，表示显示的行数
				}
	
				.info {
					color: #666666;
					font-size: 22rpx;
					margin: 10rpx 0;
				}
	
				.eye {
					color: #C0C4CC;
					font-size: 20rpx;
				}
			}
		}
	}
</style>